import {renderEngin} from "./function/renderEngin";

export function addMassMark(map, data_content, that) {
    //加载PointSimplifier，loadUI的路径参数为模块名中 'ui/' 之后的部分 
    AMapUI.loadUI(['misc/PointSimplifier'], function (PointSimplifier) {

        if (!PointSimplifier.supportCanvas) {
            return;
        }

        //启动页面
        initPage(PointSimplifier, map, data_content, that);
    });
}

function initPage(PointSimplifier, map, data_content, that) {
    //创建组件实例
    var pointSimplifierIns = new PointSimplifier({
        map: map, //关联的map
        getPosition: function (dataItem) {
            //返回数据项的经纬度，AMap.LngLat实例或者经纬度数组
            return dataItem.lnglat;
        },
        getHoverTitle: function (dataItem) {
            //返回数据项的Title信息，鼠标hover时显示
            return dataItem.markName;
        },
        renderOptions: renderEngin(),
        zIndex: 777,
        autoSetFitView: false
    });
    that.pointSimplifierIns = pointSimplifierIns;

    //设置数据源，data需要是一个数组
    pointSimplifierIns.setData(data_content);

    //监听事件
    pointSimplifierIns.on('pointClick', function (e, record) {
        // let TowerId = record.data.TowerId;
        that.$emit("clickSpot", record.data);
        // that.$router.push({ name: "tower", query: { index: TowerId } });
    });
    map.setCenter(data_content[0].lnglat);
}

export function updateMassmark(map, data_content, that) {
    that.pointSimplifierIns.setData(data_content);
    map.setCenter(data_content[0].lnglat);
}